package com.generator.purchaseManage.purchaseOrderManage.service.lmpl;


import com.generator.purchaseManage.purchaseOrderManage.pojo.Brand;
import com.generator.purchaseManage.purchaseOrderManage.pojo.Product;
import com.generator.purchaseManage.purchaseOrderManage.pojo.Type;
import com.generator.purchaseManage.purchaseOrderManage.pojo.CPurchaseCon1;
import com.generator.purchaseManage.purchaseOrderManage.pojo.IncomingWarehouse;
import com.generator.purchaseManage.purchaseOrderManage.service.purchaseOrderManageService;
import com.generator.purchaseManage.purchaseOrderManage.dao.purchaseOrderManageDao;
import com.generator.util.PageModel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class purchaseOrderManageServiceImpl implements purchaseOrderManageService {

    @Autowired
    private purchaseOrderManageDao purchaseOrderManageDao;

    public purchaseOrderManageDao getPurchaseOrderManageDao() {
        return purchaseOrderManageDao;
    }

    public void setPurchaseOrderManageDao(purchaseOrderManageDao purchaseOrderManageDao) {
        this.purchaseOrderManageDao = purchaseOrderManageDao;
    }

    @Override
    public List<CPurchaseCon1> getAllPurchaseOrderManage(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.getAllPurchaseOrderManage(purchase);
    }

    @Override
    public PageModel<CPurchaseCon1> getAllPurchaseOrderManage(CPurchaseCon1 purchase, PageModel<CPurchaseCon1> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0 ? 10 : pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<CPurchaseCon1> list = purchaseOrderManageDao.getAllPurchaseOrderManage(purchase);

        PageInfo<CPurchaseCon1> pageInfo = new PageInfo<CPurchaseCon1>(list);

        pageModel.setData(new ArrayList<CPurchaseCon1>(list));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());

        return pageModel;
    }

    @Override
    public int addPurchaseOrderManage(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.addPurchaseOrderManage(conn);
    }

    @Override
    public int addPurchaseOrderManage2(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.addPurchaseOrderManage2(conn);
    }

    @Override
    public CPurchaseCon1 getOnePurchaseOrderManage(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.getOnePurchaseOrderManage(conn);
    }

    @Override
    public int deletePurchaseOrderManage(String id) {
        return purchaseOrderManageDao.deletePurchaseOrderManage(id);
    }

    @Override
    public List<CPurchaseCon1> vaguePurchaseOrderManage(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.vaguePurchaseOrderManage(conn);
    }

    @Override
    public PageModel<CPurchaseCon1> vaguePurchaseOrderManage(CPurchaseCon1 conn, PageModel<CPurchaseCon1> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0 ? 10 : pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());
        List<CPurchaseCon1> userList = purchaseOrderManageDao.vaguePurchaseOrderManage(conn);
        PageInfo<CPurchaseCon1> pageInfo = new PageInfo<CPurchaseCon1>(userList);

        pageModel.setData(new ArrayList<CPurchaseCon1>(userList));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());

        return pageModel;
    }

    // 查询采购单信息下面部分
    @Override
    public CPurchaseCon1 getOnePurchaseOrderManageDown(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.getOnePurchaseOrderManageDown(conn);
    }

    // 修改采购单管理列表回显数据
    @Override
    public CPurchaseCon1 updateGetDatePurchase(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.updateGetDatePurchase(conn);
    }

    // 修改采购单管理列表数据(c_details)
    @Override
    public int updatePurchaseOrder(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.updatePurchaseOrder(conn);
    }

    @Override
    public int updatePurchaseOrder2(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.updatePurchaseOrder2(conn);
    }

    // 采购单入库详情
    @Override
    public CPurchaseCon1 purchaseWarehousingDetails(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.purchaseWarehousingDetails(conn);
    }

    // 查看入货仓库
    @Override
    public IncomingWarehouse getIncomingWarehouse(IncomingWarehouse conn) {
        return purchaseOrderManageDao.getIncomingWarehouse(conn);
    }

    @Override
    public int sendApproval(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.sendApproval(conn);
    }

    @Override
    public List<CPurchaseCon1> queryAllUnapproved(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.queryAllUnapproved(purchase);
    }

    @Override
    public PageModel<CPurchaseCon1> queryAllUnapproved(CPurchaseCon1 purchase, PageModel<CPurchaseCon1> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0 ? 10 : pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<CPurchaseCon1> list = purchaseOrderManageDao.queryAllUnapproved(purchase);

        PageInfo<CPurchaseCon1> pageInfo = new PageInfo<CPurchaseCon1>(list);

        pageModel.setData(new ArrayList<CPurchaseCon1>(list));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());

        return pageModel;
    }

    @Override
    public CPurchaseCon1 queryOneUnapproved(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.queryOneUnapproved(conn);
    }

    @Override
    public CPurchaseCon1 queryOneUnapprovedDown(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.queryOneUnapprovedDown(conn);
    }

    @Override
    public int purchaseOrderReviewAndSubmission(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.purchaseOrderReviewAndSubmission(conn);
    }

    @Override
    public List<CPurchaseCon1> vaguePurchaseOrderReview(CPurchaseCon1 conn) {
        return purchaseOrderManageDao.vaguePurchaseOrderReview(conn);
    }

    @Override
    public PageModel<CPurchaseCon1> vaguePurchaseOrderReview(CPurchaseCon1 conn, PageModel<CPurchaseCon1> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0 ? 10 : pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<CPurchaseCon1> list = purchaseOrderManageDao.vaguePurchaseOrderReview(conn);

        PageInfo<CPurchaseCon1> pageInfo = new PageInfo<CPurchaseCon1>(list);

        pageModel.setData(new ArrayList<CPurchaseCon1>(list));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());

        return pageModel;
    }

    @Override
    public List<CPurchaseCon1> queryAllBrands(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.queryAllBrands(purchase);
    }

    @Override
    public List<CPurchaseCon1> queryAllTypes(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.queryAllTypes(purchase);
    }

    @Override
    public List<CPurchaseCon1> queryAllModels(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.queryAllModels(purchase);
    }

    @Override
    public List<CPurchaseCon1> queryAllFirms(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.queryAllFirmNames(purchase);
    }

    @Override
    public List<CPurchaseCon1> queryAllFirmNames(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.queryAllFirmNames(purchase);
    }

    //添加，修改页面加载完成查询所有品牌
    public List<Brand> queryBrand(){
        return purchaseOrderManageDao.queryBrand();
    }

    //根据品牌查询类型
    public List<Type> queryTypeByBrand(Brand brand){
        return purchaseOrderManageDao.queryTypeByBrand(brand);
    }

    //根据类型查询型号
    public List<Product> queryModelByType(Type type){
        return purchaseOrderManageDao.queryModelByType(type);
    }

    //根据商品id查商品信息
    public Product queryProductDetail(Product product){
        return purchaseOrderManageDao.queryProductDetail(product);
    }

    @Override
    public CPurchaseCon1 getProductId(CPurchaseCon1 purchase) {
        return purchaseOrderManageDao.getProductId(purchase);
    }


}
